package com.my.chapter15;

import java.util.Date;
import java.util.Random;

public class practice37 {
    public static void main(String[] args) {
        Mixin2 mixin1 = new Mixin2(), mixin2 = new Mixin2();
        mixin1.set("test string 1");
        mixin2.set("test string 2");
        System.out.println(mixin1.get() + " " +
                mixin1.getStamp() + " " +
                mixin1.getSerialNumber() + " " + mixin1.getColor());
        System.out.println(mixin2.get() + " " +
                mixin2.getStamp() + " " +
                mixin2.getSerialNumber() + " " + mixin2.getColor());
    }
}

interface TimeStamped{ long getStamp(); }

class TimeStampedImp implements TimeStamped{
    private final long timeStamp;
    public TimeStampedImp(){
        timeStamp = new Date().getTime();
    }

    @Override
    public long getStamp() {
        return timeStamp;
    }
}

interface SerialNumbered{ long getSerialNumber(); }

class SerialNumberedImp implements SerialNumbered{
    private static long counter = 1;
    private final long serialNumber = counter++;

    @Override
    public long getSerialNumber() {
        return serialNumber;
    }
}

interface Basic{
    public void set(String val);
    public String get();
}

class BasicImp implements Basic{
    private String value;

    @Override
    public void set(String val) {
        value = val;
    }

    @Override
    public String get() {
        return value;
    }
}

class Mixin extends BasicImp
    implements TimeStamped,SerialNumbered{
    private TimeStamped timeStamp = new TimeStampedImp();
    private SerialNumbered serialNumber = new SerialNumberedImp();

    @Override
    public long getStamp() {
        return timeStamp.getStamp();
    }

    @Override
    public long getSerialNumber() {
        return serialNumber.getSerialNumber();
    }
}

interface Colored { String getColor(); }

class ColoredImp implements Colored {
    public String getColor() { return "蓝色"; }
}

class Mixin2 extends Mixin implements Colored {
    private Colored colored = new ColoredImp();
    public String getColor() { return colored.getColor(); }
}